﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IRC.NET.Commands
{
    public abstract class CommandBase : ICommand
    {
        private string _prefix;
        private bool _requiresResponse;
        private Dictionary<string, object> _parameters;

        protected string Prefix
        {
            get
            {
                return (this._prefix);
            }
        }

        protected Dictionary<string, object> Parameters
        {
            get
            {
                return(this._parameters);
            }
        }

        public bool RequiresResponse
        {
            get
            {
                return (this._requiresResponse);
            }
        }

        public CommandBase(string prefix, bool requiresResponse)
        {
            this._prefix = prefix;
            this._requiresResponse = requiresResponse;
            this._parameters = new Dictionary<string, object>();
        }

        public virtual string ToString()
        {
            StringBuilder command = new StringBuilder();
            command.Append(this._prefix);

            foreach (object obj in this._parameters.Values)
            {
                command.Append(" " + obj.ToString());
            }

            command.Append("\n");

            return (command.ToString());
        }

        protected void SetParameter(string name, object parameter)
        {
            if (this._parameters.ContainsKey(name))
            {
                this._parameters[name] = parameter;
            }
            else
            {
                this._parameters.Add(name, parameter);
            }
        }
    }
}
